<template>
    <div id="app">
        <el-tabs v-model="activeName" @tab-click="handleTabClick">
            <el-tab-pane label="楼栋管理" name="tab1">
                位置名称 <el-input v-model="showLocationName" placeholder="请输入内容" style="width: 200px;"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                <el-button @click="resetDormitory"><i class="el-icon-refresh">重置</i></el-button>
                <el-row>
                    <br>
                    <el-col :span="15">
                        <el-button type="primary" style="font-size: 15px;height: 35px;" @click.native="dialogFormVisible"><i class="el-icon-plus"></i> 添加楼栋</el-button>
                    </el-col>
                </el-row>
                <br>
                <el-table :data="sysDormitoryList" style="width: 100%">
                    <el-table-column prop="id" label="序号" width="250">
                    </el-table-column>
                    <el-table-column prop="locationName" label="位置名称" width="250">
                    </el-table-column>
                    <el-table-column prop="floorNumber" label="层数" width="250">
                    </el-table-column>
                    <el-table-column prop="levelName" label="层数名称" width="250">
                    </el-table-column>
                    <el-table-column prop="dormitory" label="类型" width="250">
                    </el-table-column>
                    <el-table-column prop="address" label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" @click.native="upd(scope.row)" circle></el-button>
                        <el-button type="danger" icon="el-icon-delete" @click.native="del(scope.row.id)" circle></el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <div style="margin-top: 30px;margin-left: 1150px;" v-if="pageCount>=1">
                    <el-button-group>
                        <el-button type="primary" icon="el-icon-arrow-left" @click="prevPage">上一页</el-button>
                        <el-button><span>{{pageNum}} / {{pageCount}}</span></el-button>
                        <el-button type="primary" @click="nextPage">下一页<i class="el-icon-arrow-right el-icon--right"></i></el-button>
                    </el-button-group>
                </div>
                <el-row v-if="showDormitory">
                    <el-dialog title="添加空间位置" :visible.sync="showDormitory" width="30%">
                        <el-form :model="dormitory" label-width="80px">
                            <el-form-item label="位置名称">
                                <el-input v-model="locationName" @change="nameChange"></el-input>
                            </el-form-item>
                            <el-form-item label="层级名称">
                                <el-input v-model="levelName" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="层数">
                                <template>
                                    <el-input-number v-model="floorNumber" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
                                </template>
                            </el-form-item>
                            <el-form-item label="位置类型">
                                <el-radio v-model="radio" label="楼栋">楼栋</el-radio>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="addDormitory">确 定</el-button>
                            <el-button @click="showDormitory = false">取 消</el-button>
                        </span> 
                    </el-dialog>
                </el-row>
                <el-row v-if="updDormitory===true">
                    <el-dialog title="修改空间位置" :visible.sync="updDormitory" width="30%">
                        <el-form :model="dormitory" label-width="80px">
                                
                            <el-form-item label="位置名称">
                                <el-input v-model="locationName" @change="nameChange"></el-input>
                            </el-form-item>
                            <el-form-item label="层级名称">
                                <el-input v-model="levelName" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="层数">
                                <template>
                                    <el-input-number v-model="floorNumber" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
                                </template>
                            </el-form-item>
                            <el-form-item label="位置类型">
                                <el-radio v-model="radio" label="楼栋">楼栋</el-radio>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button type="primary" @click.native="updDormitoryById">确 定</el-button>
                            <el-button @click="updDormitory = false">取 消</el-button>
                        </span> 
                    </el-dialog>
                </el-row>
            </el-tab-pane>
            <el-tab-pane label="教室管理" name="tab2">
                位置名称 <el-input v-model="showCRLocationName" placeholder="请输入内容" style="width: 200px;"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="searchCR">搜索</el-button>
                <el-button @click="resetCR"><i class="el-icon-refresh">重置</i></el-button>
                <el-row>
                    <br>
                    <el-col :span="15">
                        <el-button type="primary" style="font-size: 15px;height: 35px;" @click.native="crFormVisible"><i class="el-icon-plus"></i> 添加教室</el-button>
                    </el-col>
                </el-row>
                <br>
                <el-table :data="sysClassroomList" style="width: 100%">
                    <el-table-column prop="id" label="序号" width="250"></el-table-column>
                    <el-table-column prop="locationName" label="位置名称" width="250"></el-table-column>
                    <el-table-column prop="levelName" label="层数名称" width="250"></el-table-column>
                    <el-table-column prop="classroom"  label="类型"  width="250"></el-table-column>
                    <el-table-column prop="address" label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" @click="updCR(scope.row)" circle></el-button>
                        <el-button type="danger" icon="el-icon-delete" @click.native="delClassRoom(scope.row.id)" circle></el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <div style="margin-top: 30px;margin-left: 1150px;" v-if="pageCount>=1">
                    <el-button-group>
                        <el-button type="primary" icon="el-icon-arrow-left" @click="crPrevPage">上一页</el-button>
                        <el-button><span>{{pageNum}} / {{pageCount}}</span></el-button>
                        <el-button type="primary" @click="crNextPage">下一页<i class="el-icon-arrow-right el-icon--right"></i></el-button>
                    </el-button-group>
                </div>
                <el-row v-if="showClassRoom">
                    <el-dialog title="添加空间位置" :visible.sync="showClassRoom" width="30%">
                        <el-form :model="classRoom" label-width="100px">
                            <el-form-item label="位置名称">
                                <el-input v-model="crLocationName"></el-input>
                            </el-form-item>
                            <el-form-item label="教室座位数" style="width: 100px;">
                                <template>
                                    <el-input-number v-model="crSeatsNumber" @change="handleChange" :min="1" :max="50" label="描述文字"></el-input-number>
                                </template>
                            </el-form-item>
                            <el-form-item label="上层位置">
                                <!-- <el-cascader :options="sysDormitoryListAll" v-model="selectedOptions" @click.native="getSysDormitoryAll" @change="handChange" :show-all-levels="false" >
                                    <template slot-scope="{data}">
                                        <span @click="toggleChildren(data)">{{ data.label }}</span>
                                        <span v-if="data.isChildrenVisible" class="children-span">{{ data.children }}</span>
                                    </template>
                                </el-cascader> -->
                                
                                <el-select v-model="sysDormitory.id" placeholder="请选择" @click.native="getSysDormitoryAll">
                                    <el-option  v-for="sysDormitory in sysDormitoryListAll" :key="sysDormitory.id" :label="sysDormitory.locationName"
                                        :value="sysDormitory.id" @click.native="addSeat(sysDormitory)" >
                                    </el-option>
                                </el-select> <br>
                                <el-select v-model="seatID" placeholder="请选择">
                                    <el-option v-for="item in tempClass" :key="item.value" :label="item.name"
                                        :value="item.value" @click.native="classChange">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="层级名称">
                                <el-input v-model="crLevelName" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="位置类型">
                                <el-radio v-model="radio1" label="教室">教室</el-radio>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="addClassRoom">确 定</el-button>
                            <el-button @click="showClassRoom = false">取 消</el-button>
                        </span> 
                    </el-dialog>
                </el-row>
                <el-row v-if="updClassRoom">
                    <el-dialog title="修改空间位置" :visible.sync="updClassRoom" width="30%">
                        <el-form :model="classRoom" label-width="100px">
                                
                            <el-form-item label="位置名称">
                                <el-input v-model="crLocationName"></el-input>
                            </el-form-item>
                            <el-form-item label="教室座位数" style="width: 100px;">
                                <template>
                                    <el-input-number v-model="crSeatsNumber" @change="handleChange" :min="1" :max="50" label="描述文字"></el-input-number>
                                </template>
                            </el-form-item>
                            <el-form-item label="上层位置">
                                <el-select v-model="sysDormitory.id" placeholder="请选择" @click.native="getSysDormitoryAll">
                                    <el-option  v-for="sysDormitory in sysDormitoryListAll" :key="sysDormitory.id" :label="sysDormitory.locationName"
                                        :value="sysDormitory.id" @click.native="addSeat(sysDormitory)" >
                                    </el-option>
                                </el-select> <br>
                                <el-select v-model="seatID" placeholder="请选择">
                                    <el-option v-for="item in tempClass" :key="item.value" :label="item.name"
                                        :value="item.value" @click.native="classChange">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="层级名称">
                                <el-input v-model="crLevelName" :disabled="true"></el-input>
                            </el-form-item>
                            
                            <el-form-item label="位置类型">
                                <el-radio v-model="radio1" label="教室">教室</el-radio>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="updClassRoomById">确 定</el-button>
                            <el-button @click="updClassRoom = false">取 消</el-button>
                        </span> 
                    </el-dialog>
                </el-row>
            </el-tab-pane>
            
            <el-tab-pane label="宿舍管理" name="tab3">
                位置名称 <el-input v-model="showHLocationName" placeholder="请输入内容" style="width: 200px;"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="searchHostel">搜索</el-button>
                <el-button @click="resetHostel"><i class="el-icon-refresh">重置</i></el-button>
                <el-row>
                    <br>
                    <el-col :span="15">
                        <el-button type="primary" style="font-size: 15px;height: 35px;" @click.native="hFormVisible"><i class="el-icon-plus"></i> 添加宿舍</el-button>
                    </el-col>
                </el-row>
                <br>
                <el-table :data="sysHostelList" style="width: 100%">
                    <el-table-column prop="id" label="序号" width="250"></el-table-column>
                    <el-table-column prop="locationName" label="位置名称" width="250"></el-table-column>
                    <el-table-column prop="levelName" label="层数名称" width="250"></el-table-column>
                    <el-table-column prop="hostel"  label="类型"  width="250"></el-table-column>
                    <el-table-column prop="address" label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" @click.native="updH(scope.row)" circle></el-button>
                        <el-button type="danger" icon="el-icon-delete" @click.native="delHostel(scope.row.id)" circle></el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <div style="margin-top: 30px;margin-left: 1150px;" v-if="pageCount>=1">
                    <el-button-group>
                        <el-button type="primary" icon="el-icon-arrow-left" @click="hPrevPage">上一页</el-button>
                        <el-button><span>{{pageNum}} / {{pageCount}}</span></el-button>
                        <el-button type="primary" @click="hNextPage">下一页<i class="el-icon-arrow-right el-icon--right"></i></el-button>
                    </el-button-group>
                </div>
                <el-row v-if="showHostel===true">
                    <el-dialog title="添加空间位置" :visible.sync="showHostel" width="30%">
                        <el-form :model="classRoom" label-width="100px">
                            <el-form-item label="位置名称">
                                <el-input v-model="crLocationName"></el-input>
                            </el-form-item>
                            <el-form-item label="宿舍床位数" style="width: 100px;">
                                <template>
                                    <el-input-number
                                        v-model="seatsNumber"
                                        @change="hostelChange"
                                        @keydown.up.prevent="increaseBedCount"
                                        @keydown.down.prevent="decreaseBedCount"
                                        :min="min"
                                        :max="max"
                                        label="描述文字"
                                        ></el-input-number>
                                </template>
                            </el-form-item>
                            <el-form-item label="上层位置">
                                <el-select v-model="sysDormitory.id" placeholder="请选择" @click.native="getSysDormitoryAll">
                                    <el-option  v-for="sysDormitory in sysDormitoryListAll" :key="sysDormitory.id" :label="sysDormitory.locationName"
                                        :value="sysDormitory.id" @click.native="addSeat(sysDormitory)" >
                                    </el-option>
                                </el-select> <br>
                                <el-select v-model="seatID" placeholder="请选择">
                                    <el-option v-for="item in tempClass" :key="item.value" :label="item.name"
                                        :value="item.value" @click.native="classChange">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="层级名称">
                                <el-input v-model="crLevelName" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="位置类型">
                                <el-radio v-model="radioHostel" label="宿舍">宿舍</el-radio>
                            </el-form-item>
                            <el-form-item label="床位编号">
                            <el-row :gutter="5">
                                <el-col v-for="(number, index) in bedNumbers" :key="index">
                                    <el-card style="height: 60px;width: 250px;">
                                        <div>床位{{ number }}<el-tag type="success">上铺</el-tag>
                                            <el-tag type="info">未使用</el-tag>
                                        </div>
                                    </el-card>
                                </el-col>
                            </el-row>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="addHostel">确 定</el-button>
                            <el-button @click="showHostel = false">取 消</el-button>
                        </span> 
                    </el-dialog>
                </el-row>
                <el-row v-if="updHostel===true">
                    <el-dialog title="修改空间位置" :visible.sync="updHostel" width="30%">
                        <el-form :model="hostel" label-width="100px">
                            <el-form-item label="位置名称">
                                <el-input v-model="crLocationName"></el-input>
                            </el-form-item>
                            <el-form-item label="宿舍床位数" style="width: 100px;">
                                <template>
                                    <el-input-number
                                        v-model="seatsNumber"
                                        @change="hostelChange"
                                        @keydown.up.prevent="increaseBedCount"
                                        @keydown.down.prevent="decreaseBedCount"
                                        :min="min"
                                        :max="max"
                                        label="描述文字"
                                        ></el-input-number>
                                </template>
                            </el-form-item>
                            <el-form-item label="上层位置">
                                <el-select v-model="sysDormitory.id" placeholder="请选择" @click.native="getSysDormitoryAll">
                                    <el-option  v-for="sysDormitory in sysDormitoryListAll" :key="sysDormitory.id" :label="sysDormitory.locationName"
                                        :value="sysDormitory.id" @click.native="addSeat(sysDormitory)" >
                                    </el-option>
                                </el-select> <br>
                                <el-select v-model="seatID" placeholder="请选择">
                                    <el-option v-for="item in tempClass" :key="item.value" :label="item.name"
                                        :value="item.value" @click.native="classChange">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="层级名称">
                                <el-input v-model="crLevelName" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="位置类型">
                                <el-radio v-model="radioHostel" label="宿舍">宿舍</el-radio>
                            </el-form-item>
                            <el-form-item label="床位编号">
                            <el-row :gutter="5">
                                <el-col v-for="(number, index) in bedNumbers" :key="index">
                                    <el-card style="height: 60px;width: 250px;">
                                        <div>床位{{ number }}<el-tag type="success">上铺</el-tag>
                                            <el-tag type="info">未使用</el-tag>
                                        </div>
                                    </el-card>
                                </el-col>
                            </el-row>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="updHostelById">确 定</el-button>
                            <el-button @click="updHostel = false">取 消</el-button>
                        </span> 
                    </el-dialog>
                </el-row>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<script>

    import axios from 'axios';
    export default {
        name: 'formManage',
        props: {
            min: {
                type: Number,
                default: 1
            },
            max: {
                type: Number,
                default: 6
            },
            initialValue: {
                type: Number,
                default: 1
            }
        },
        data () {
            return {
                tempClass:[],
                seatID:'',
                data:null,
                activeName: 'tab1',
                pageNum:1,
                pageSize:1,
                pageCount:1,
                locationName:'',
                levelName:'',
                showLocationName:'',
                showDormitory:false,
                floorNumber:1,
                radio:1,
                dormitory:{},
                sysDormitoryList:[],
                sysClassroomList:[],
                showCRLocationName:'',
                showClassRoom:false,
                radio1:'教室',
                crLocationName:'',
                crSeatsNumber:'',
                crLevelName:'',
                sysDormitoryListAll:[],
                classRoom:{},
                children:[],
                selectedOptions:null,
                updDormitory:false,
                updClassRoom:false,
                sysClassroom:{},
                selectedSysDormitory:'',
                sysDormitory:{},
                showHostel:false,
                radioHostel:'宿舍',
                hSeatsNumber:1,
                seatsNumber: this.initialValue,
                bedCount: this.initialValue,
                bedNumbers: [this.initialValue],
                showHLocationName:'',
                hLocationName:'',
                hLevelName:'',
                sysHostel:{},
                updHostel:false,
                numberFloors:''
            }
        },
        created () {
            this.getSysDormitory(1);
        },
        methods: {
            
            handleChange(value) {
                console.log(value);
            },
            dialogFormVisible(){
                this.showDormitory = true;
                this.locationName = '';
                this.levelName = '';
            },
            handleTabClick(tab) {
                this.showLocationName = '';
                this.pageCount = '';
                this.pageNum = 1;
                if(tab.name == 'tab1'){
                    this.getSysDormitory(1);
                }else if(tab.name == 'tab2'){
                    this.getSysClassroomList(1);
                }else if(tab.name == 'tab3'){
                    this.getSysHostelList(1);
                }
                console.log(tab);
            
            },
            nameChange(){
                this.levelName = this.locationName;
            },
            prevPage(){
                this.pageNum--;
                var pageNum = this.pageNum;
                if(this.pageNum >= 1){
                    this.getSysDormitory(pageNum);
                }else{
                    this.getSysDormitory(1);
                }   
            },
            nextPage(){
                this.pageNum++;
                var pageNum = this.pageNum;
                if(this.pageNum <= this.pageCount){
                    this.getSysDormitory(pageNum);
                }else{
                    this.getSysDormitory(this.pageCount);
                }                
            },
            search(){
                let pageNum =this.pageNum;
                this.getSysDormitory(pageNum);
            },
            resetDormitory(){
                this.showLocationName = '';
                this.getSysDormitory(1);
            },
            getSysDormitory(pageNum){
                console.log(this.pageNum);
                
                this.pageNum = pageNum;
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/dormitory/getSysDormitory',
                    method: 'post',
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        locationName: this.showLocationName
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    this.sysDormitoryList = response.data.data.sysDormitoryList;
                    this.pageNum = response.data.data.pageNum;
                    this.pageCount = response.data.data.pageCount;
                })
            },
            addDormitory(){
                if(this.locationName == ''){
                    this.$message.error('请输入位置名称！');
                    return;
                }
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/dormitory/addDormitory',
                    method: 'post',
                    data: {
                        locationName: this.locationName,
                        levelName: this.levelName,
                        floorNumber: this.floorNumber,
                        dormitory: this.radio
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    if(response.data.status == 200){
                        this.$message.success('楼栋信息添加成功！');
                        this.locationName = '';
                        this.levelName = '';
                        this.floorNumber = 1;
                        this.showDormitory = false;
                    }else{
                        this.$message.msg('楼栋信息添加失败！');
                    }
                    
                })
            },
            updDormitoryById(){
                if(this.locationName == ''){
                    this.$message.error('请输入位置名称！');
                    return;
                }
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/dormitory/updDormitory',
                    method: 'post',
                    data: {
                        id: this.dormitory.id,
                        locationName: this.locationName,
                        levelName: this.levelName,
                        floorNumber: this.floorNumber,
                        dormitory: this.radio
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    if(response.data.status == 200){
                        this.$message.success(response.data.msg);
                        this.getSysDormitory(1);
                    }else{
                        this.$message.error(response.data.msg);
                    }
                })
            },
            del(id){
                this.$confirm('此操作将删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.Authorization = localStorage.getItem("Authorization");
                    axios({
                        url: 'http://localhost:9002/sys/dormitory/delDormitoryById',
                        method: 'post',
                        params: {
                            id: id
                        },
                        headers: {
                            'Authorization': this.Authorization
                        }
                    })
                   .then(resp => {
                    console.log(resp);
                        if(resp.data.status == 200){
                            this.$message.success('删除成功！');
                            this.getSysDormitory(1);
                        }else{
                            this.$message.error(resp.data.msg);
                        }
                   })
                })
                
            },
            upd(row){
                this.updDormitory= true;
                this.dormitory = row;
                this.locationName = row.locationName;
                this.levelName = row.levelName;
                this.floorNumber = row.floorNumber;
                this.radio = row.dormitory;
                this.selectedOptions = row.locationName;
                console.log("修改"+this.dormitory);
            },
            crFormVisible(){
                this.crLocationName = '';
                this.levelName = '';
                this.crLevelName = '';
                this.crSeatsNumber = 1;
                this.sysDormitory = {};
                this.seatID = '';
                this.showClassRoom = true;
                
            },
            getSysClassroomList(pageNum){
                this.pageNum = pageNum;
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/classroom/getSysClassroomList',
                    method: 'post',
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        locationName: this.showCRLocationName
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
               })
                .then(response => {
                    console.log(response);
                    this.sysClassroomList = response.data.data.sysClassroomList;
                    this.pageNum = response.data.data.pageNum;
                    this.pageCount = response.data.data.pageCount;
                })
            },
            crPrevPage(){
                this.pageNum--;
                var pageNum = this.pageNum;
                if(this.pageNum >= 1){
                    this.getSysClassroomList(pageNum);
                }else{
                    this.getSysClassroomList(1);
                }   
            },
            crNextPage(){
                this.pageNum++;
                var pageNum = this.pageNum;
                if(this.pageNum <= this.pageCount){
                    this.getSysClassroomList(pageNum);
                }else{
                    this.getSysClassroomList(this.pageCount);
                }                
            },
            searchCR(){
                let pageNum =this.pageNum;
                this.getSysClassroomList(pageNum);
            },
            resetCR(){
                this.showCRLocationName = '';
                this.getSysClassroomList(1);
            },
            getSysDormitoryAll(){
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/dormitory/getSysDormitoryList',
                    method: 'post',
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    this.sysDormitoryListAll = response.data.data;
               })
            },
            classChange(){
                console.log("楼层"+this.seatID);
                this.crLevelName = this.sysDormitory.levelName+this.seatID+"楼-"+this.crLocationName;
                console.log("weiz"+this.crLevelName);
            },
            addClassRoom(){
                if(this.crLevelName == ''){
                    this.$message.error('请输入位置名称！');
                    return;
                }
                if(this.crLocationName == ''){
                    this.$message.error('请选择楼层！');
                    return;
                }
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/classroom/addSysClassroom',
                    method: 'post',
                    data: {
                        locationName: this.crLocationName,
                        levelName: this.crLevelName,
                        seatsNumber: this.crSeatsNumber,
                        classroom: this.radio1,
                        dormitoryId: this.dormitoryId,
                        numberFloors:this.seatID
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    if(response.data.status == 200){
                        this.$message.success('教室信息添加成功！');
                        this.crLocationName = '';
                        this.crLevelName = '';
                        this.crSeatsNumber = 1;
                        this.showClassRoom = false;
                        this.getSysClassroomList(1);
                    }else{
                        this.$message.error('教室信息添加失败！');
                    }
                })
            },
            
            updCR(row){
                console.log(row);
                this.updClassRoom = true;
                console.log(this.updClassRoom)
                this.sysClassroom = row;
                this.crLevelName = this.sysClassroom.levelName;
                this.crLocationName = this.sysClassroom.locationName;
                this.crSeatsNumber = this.sysClassroom.seatsNumber;
                this.radio1 = this.sysClassroom.classroom;
                this.dormitoryId = this.sysClassroom.dormitoryId;
                console.log(this.sysDormitory);
                this.sysDormitory.id = this.sysClassroom.locationName;

                this.showUpdClassRoom = true;
                
            },
            updClassRoomById(){
                if(this.crLocationName == ''){
                    this.$message.error('请输入位置名称');
                    return;
                }
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/classroom/updSysClassroom',
                    method: 'post',
                    data: {
                        locationName: this.crLocationName,
                        levelName: this.crLevelName,
                        seatsNumber: this.crSeatsNumber,
                        classroom: this.radio1,
                        dormitoryId: this.dormitoryId,
                        id:this.sysClassroom.id,
                        numberFloors:this.seatID
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    if(response.data.status == 200){
                        this.$message.success('更新成功！');
                        this.crLocationName = '';
                        this.crLevelName = '';
                        this.crSeatsNumber = 1;
                        this.showUpdClassRoom = false;
                        this.getSysClassroomList(1);
                    }else{
                        this.$message.error('更新失败！');
                    }
                })
            },
            delClassRoom(id){
                this.$confirm('此操作将删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.Authorization = localStorage.getItem("Authorization");
                    axios({
                        url: 'http://localhost:9002/sys/classroom/delClassroomById',
                        method: 'post',
                        params: {
                            id: id
                        },
                        headers: {
                            'Authorization': this.Authorization
                        }
                    })
                   .then(resp => {
                    console.log(resp);
                        if(resp.data.status == 200){
                            this.$message.success('删除成功！');
                            this.getSysClassroomList(1);
                        }else{
                            this.$message.error(resp.data.msg);
                        }
                   })
                })
                
            },
            addSeat(sysDormitory) {
                this.dormitoryId = sysDormitory.id;
                this.sysDormitory.levelName = sysDormitory.levelName;
                this.sysDormitory.floorNumber = sysDormitory.floorNumber;
                const id = sysDormitory.floorNumber;
                this.tempClass = [];
                // 使用for循环来填充数组  
                for (let i = 1; i <= id; i++) {
                    // 创建一个对象来表示楼层，包含楼层名称、id和value字段  
                    let floorObject = {
                        name: `${i}楼`, // 楼层名称，例如“一楼”，“二楼”等  
                        value: i        // 楼层的value，这里也简单地使用楼层数作为value  
                    };
                    // 将楼层对象添加到数组中  
                    this.tempClass.push(floorObject);
                }
            },
            hFormVisible(){
                this.crLocationName = '';
                this.levelName = '';
                this.crLevelName = '';
                this.crSeatsNumber = 1;
                this.sysDormitory = {};
                this.seatID = '';
                this.showHostel = true;
            },
            hostelChange() {
                const seatNumber = this.seatsNumber;
                const currentBedCount = this.bedCount;
                if (seatNumber > currentBedCount) {
                    const bedsToAdd = seatNumber - currentBedCount;
                    for (let i = 0; i < bedsToAdd; i++) {
                    this.increaseBedCount();
                    }
                } else if (seatNumber < currentBedCount) {
                    const bedsToRemove = currentBedCount - seatNumber;
                    for (let i = 0; i < bedsToRemove; i++) {
                    this.decreaseBedCount();
                    }
                }
                this.$emit('input', this.seatsNumber);
            },
            increaseBedCount() {
                if (this.bedCount < this.max) {
                    this.bedCount++;
                    this.bedNumbers.push(this.bedCount);
                    this.seatsNumber = this.bedCount;
                }
            },
            decreaseBedCount() {
                if (this.bedCount > this.min) {
                    this.bedCount--;
                    this.bedNumbers.pop();
                    this.seatsNumber = this.bedCount;
                }
            },
            getSysHostelList(pageNum){
                this.pageNum = pageNum;
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/hostel/getSysHostelList',
                    method: 'post',
                    params:{
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        locationName: this.showHLocationName
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    this.sysHostelList = response.data.data.sysHostelList;
                    this.pageNum = response.data.data.pageNum;
                    this.pageCount = response.data.data.pageCount;
                    
                })
            },
            hNextPage(){
                this.pageNum++;
                var pageNum = this.pageNum;
                if(this.pageNum <= this.pageCount){
                    this.getSysHostelList(pageNum);
                }else{
                    this.getSysHostelList(this.pageCount);
                }    
            },
            hPrevPage(){
                this.pageNum--;
                var pageNum = this.pageNum;
                if(this.pageNum >= 1){
                    this.getSysHostelList(pageNum);
                }else{
                    this.getSysHostelList(1);
                }   
            },
            searchHostel(){
                let pageNum = this.pageNum;
                this.getSysHostelList(pageNum);
            },
            resetHostel(){
                this.showHLocationName = "";
                this.getSysHostelList(1);
            },
            addHostel(){
                if(this.crLocationName == ''){
                    this.$message.error("请输入位置名称");
                    return;
                }
                if(this.crLevelName == ''){
                    this.$message.error("请选择楼层");
                    return;
                }
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/hostel/addSysHostel',
                    method: 'post',
                    data: {
                        locationName: this.crLocationName,
                        levelName: this.crLevelName,
                        bedCount: this.seatsNumber,
                        hostel: this.radioHostel,
                        dormitoryId: this.dormitoryId,
                        numberFloors:this.seatID
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    if(response.data.status == 200){
                        this.$message.success("添加成功");
                        this.showHostel = false;
                        this.getSysHostelList(1);
                    }else if(response.data.status == 500){
                        this.$message.error(response.data.msg);
                    }
                })
            },
            delHostel(id){
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.Authorization = localStorage.getItem("Authorization");
                    axios({
                        url: 'http://localhost:9002/sys/hostel/delSysHostelById',
                        method: 'post',
                        params: {id: id},
                        headers: {
                            'Authorization': this.Authorization
                        }
                    })
                    .then(response => {
                        console.log(response);
                        if(response.data.status == 200){
                            this.$message.success("删除成功");
                            this.getSysHostelList(1);
                        }else{
                            this.$message.error(response.data.msg);
                        }
                    })
                })
            },
            updH(row){
                this.updHostel = true;
                this.sysHostel = row;
                this.radioHostel = this.sysHostel.hostel;
                this.crLevelName = this.sysHostel.levelName;
                this.crLocationName = this.sysHostel.locationName;
                this.seatsNumber = this.sysHostel.bedCount;
                this.dormitoryId = this.sysHostel.dormitoryId;
                this.seatID = this.sysHostel.numberFloors;
                console.log(this.sysDormitory);
                this.sysDormitory.id = this.sysHostel.locationName;
                this.hostelChange();
                // this.showUpdHostel = true;
            },
            updHostelById(){
                if(this.crLocationName == ''){
                    this.$message.error("请输入位置名称");
                    return;
                }
                this.Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/hostel/updSysHostelById',
                    method: 'post',
                    data: {
                        id: this.sysHostel.id,
                        locationName: this.crLocationName,
                        levelName: this.crLevelName,
                        bedCount: this.seatsNumber,
                        hostel: this.radioHostel,
                        dormitoryId: this.dormitoryId,
                        numberFloors:this.seatID
                    },
                    headers: {
                        'Authorization': this.Authorization
                    }
                })
                .then(response => {
                    console.log(response);
                    if(response.data.status == 200){
                        this.$message.success("更新成功");
                        this.crLocationName = '';
                        this.crLevelName = '';
                        this.seatsNumber = '';
                        this.updHostel = false;
                        this.getSysHostelList(1);
                    }else{
                        this.$message.error(response.data.msg);
                    }
                })
            }
        }
    }
</script>
<style scoped>
.children-span {
  display: block;
  margin-left: 20px;
}
</style>